package com.dt76.smallloanbackenduser.controller.lhuaw;

import com.dt76.smallloanbackenduser.remote.lhuaw.ArticleManagementtest;
import com.dt76.smallloanbackenduser.utils.Page;
import com.dt76.smallloanbackenduser.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("/lhuaw")
public class ArticleManagementController {
    @Autowired
    private ArticleManagementtest articleManagementtest;

@RequestMapping("/qryAllArticle")
public String qryAllApplication(Model model){
    model.addAttribute("ArticleManagementList",articleManagementtest.qryAllArticle());
    System.out.println("调用成功");
    System.out.println(articleManagementtest.qryAllArticle());
    return "pages/lhuaw/ArticleManagement";
}
@RequestMapping("/qryAllArticleAll")
public String qryConditionPageAll(Model model, Integer currentPageNo,
                                  @RequestParam(value ="articleTitle",required = false)String articleTitle,
                                  @RequestParam(value = "classification",required = false)String classification
                                  ){
   if (currentPageNo <= 0) {
        currentPageNo = 1;
   }
    String paramarticleTitle= "";
    String paramclassification="";
    if(articleTitle != null && ! articleTitle.equals("")){
        paramarticleTitle ="%"+articleTitle+"%";
    }
    if(classification !=null && ! classification.equals("")){
        paramclassification ="%"+classification+"%";
    }
    Page page = articleManagementtest.qryAllArticleAll(currentPageNo,paramarticleTitle,paramclassification);
    model.addAttribute("qryArticleManagementList",page.getRows());
    model.addAttribute("page",page);
    model.addAttribute("articleTitle",articleTitle);
    model.addAttribute("classification",classification);
    System.out.println(page.getRows());
    return "pages/lhuaw/ArticleManagement";
}
    @RequestMapping("/delArticle/{articleId}")
    @ResponseBody
    public Result delArticle(@PathVariable String articleId){
        return articleManagementtest.delArticle(Integer.parseInt(articleId));
    }
//    @RequestMapping("/addSystem")
//    @ResponseBody
//    public Result addSystem(
//            @RequestParam("messageTitle") String messageTitle,
//            String sId,
//            SystemMessage systemMessage) {
//        Result result = new Result();
//        if (sId.equals("0")) {
//            systemMessage.setMessageTitle(messageTitle);
//            //调用新增接口
//            result = systemMessagetest.addSystem(systemMessage);
//
//            if (result.isSuccess()) {
//                //刷新全部的信息
//                result.setMsg("添加成功");
//            } else {
//                result.setMsg("添加失败");
//            }
//        }
//        return result;
//    }
//    @RequestMapping("/seeSystem/{sId}")
//    @ResponseBody
//    public SystemMessage seeSystem(@PathVariable String sId){
//        //调用查询接口
//        System.out.println(Integer.parseInt(sId));
//        System.out.println(systemMessagetest.seeSystem(Integer.parseInt(sId)));
//        return systemMessagetest.seeSystem(Integer.parseInt(sId));
//    }

}
